<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 找出一个整数数组中第 K 大的整数 -->
    <script>
      var findKthLargest = function (nums, k) {
        // 先使用插入排序
        insertSort(nums)
        let ans = nums.splice(k - 1, 1)
        return ans
      }

      var insertSort = function (nums) {
        let j
        for (let i = 1; i < nums.length; i++) {
          let cur = nums[i]
          for (j = i; j >= 1; j--) {
            if (nums[j - 1] < cur) {
              nums[j] = nums[j - 1]
            } else {
              break
            }
          }
          nums[j] = cur
        }
      }
      console.log(findKthLargest(['3', '0', '-7', '-10'], 2))
    </script>
  </body>
</html>
